<template>
  <div id="dialogIntegralAction">
    <el-dialog
      title="查看明细"
      :visible.sync="dialogData.isShow"
      width="1080px"
      @close="closeAddDialog"
    >
      <h1 class="title">任务名称：{{ taskName }}</h1>
      <!-- 顶部搜索框部分 -->
      <div class="search-box">
        <el-form ref="ruleForm" :inline="true" :model="formInline">
          <!-- 输入搜索部分 -->
          <el-form-item label="渠道分类" prop="changeClass">
            <el-select
              v-model="formInline.changeClass"
              placeholder="请选择渠道分类"
              clearable
              class="short-input"
            >
              <el-option
                v-for="item in changeClassList"
                :key="item.dictLabel"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="大鹏号" prop="dapengId">
            <el-input
              v-model="formInline.dapengId"
              placeholder="请输入大鹏号"
              size="small"
              class="numberInput"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="参与时间" prop="createTime">
            <el-date-picker
              v-model="formInline.createTime"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item class="s-btn">
            <el-button
              type="success"
              icon="el-icon-search"
              @click="toSearch('ruleForm')"
            >
              查询
            </el-button>
            <el-button type="success" plain @click="reset">
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <freshCom @searchList="searchList"></freshCom>
      <!-- 表格部分 -->
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%"
        max-height="490"
      >
        <el-table-column type="index" width="80" align="center" label="序号">
          <template slot-scope="scope">
            {{
              scope.$index
                | filterPage(searchParams.pageNum, searchParams.pageSize)
            }}
          </template>
        </el-table-column>
        <el-table-column prop="nickName" label="用户昵称"></el-table-column>
        <el-table-column prop="dpAccount" label="大鹏号"></el-table-column>
        <el-table-column prop="mobile" label="手机号"></el-table-column>
        <el-table-column prop="changeClass" label="渠道分类">
          <template slot-scope="scope">
            {{ scope.row.changeClass | filterName('strategy_channel') }}
          </template>
        </el-table-column>
        <el-table-column label="参与时间" prop="createTime"></el-table-column>
        <el-table-column prop="integralChangeNumber" label="获得积分"></el-table-column>
      </el-table>
      <!--分页-全局组件-->
      <pageCom
        :searchParams="searchParams"
        :total="total"
        @searchList="searchList"
      ></pageCom>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="closeAddDialog">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getDetailList } from '@/api/couponsIntegral/integralAction' //接口
export default {
  name: 'dialogIntegralAction',
  msg: '查看明细弹窗',
  props: ['dialogData'],
  data() {
    return {
      loading: false,
      confirmloading: false,
      taskName: '',
      id: '',
      total: 0,
      tableData: [], // table内容
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      },
      formInline: {
        dapengId: '', //大鹏号
        changeClass: '', //渠道分类
        createTime: [], //参与时间
        startTime: '', //渠道分类
        endTime: '' //渠道分类
      },
      changeClassList: [{ dictLabel: '全部', dictValue: '' }] // 渠道分类
    }
  },
  mounted() {
    this.getStatusList()
    let { taskName, id } = this.dialogData.params
    this.taskName = taskName
    this.id = id
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  methods: {
    /* 获取列表 */
    searchList() {
      this.loading = true
      const params = {}
      Object.keys(this.formInline).forEach((key) => {
        if (this.formInline[key] !== '') {
          params[key] = this.formInline[key]
        }
      })
      let obj = Object.assign({}, this.searchParams, params)
      delete obj.createTime
      getDetailList(
        this.id,
        obj,
        (response) => {
          this.loading = false
          this.tableData = response.rows
          this.total = response.total
        },
        (response) => {
          this.loading = false
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    // 搜索
    toSearch() {
      this.searchParams.pageNum = 1
      this.searchList()
    },
    /* 获取字典状态 */
    async getStatusList() {
      let data = await sysNormalDisable('strategy_channel', 'strategy_channel')
      this.changeClassList = this.changeClassList.concat(data)
      this.searchList()
    },
    // 重置
    reset() {
      this.$refs['ruleForm'].resetFields()
    },
    // 弹窗关闭事件
    closeAddDialog() {
      this.loading = false
      this.dialogData.params = null
      this.dialogData.isShow = false
    },
    /* 换页 */
    changePage(page) {
      this.searchParams.pageNum = page
      this.searchList()
    }
  }
}
</script>

<style lang="less">
#dialogIntegralAction {
  .search-box {
    padding-left: 0 !important;
  }
  .short-input {
    .el-input__inner {
      width: 100px !important;
    }
  }
}
</style>
